// import { formeditperm } from "@/api/access/access-api";

export function setCookie(cname, cvalue, time) {
    if(cvalue){
        var d = new Date();
        d.setTime(d.getTime() + time);
        var expires = "expires=" + d.toGMTString();
        document.cookie = cname + "=" + cvalue + "; " + expires;
    }
}

export function getCookie(cname) {
    if(cname){
        var name = cname + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i].trim();
            if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
        }
        return "";
    }
}

export function removeN(value){
    if(value){
        return value.replace(/(\r\n)|(\n)|(\r)/g,'');
    }
}

export function setImg(blod) {
    if(blod){
        return blod.replace(
            /^data:image\/\w+;base64,/,
            ""
        )
    }
 }

export function getImg(blod) {
    // 用类似img字段的流 跟后端说加上对应的img base64 文件流http://csc.general.paasdev.zoomlion.com/api/biz/bpmfile/getfile/0025c07c-c0c0-4f0f-a825-6c936a002617
    //blod base64 返回 图片文件流
    //van-img  直接用
    //van-uploader 需要增加 isImage:true  { url: img,isImage: true},
    //van-swipe 直接用
    if(blod){
        return `data:image/png;base64,${blod}`;
    }
}

// export function getAccess(boId,procesInstId,processDefId,processGroupId){
//     let param = {
//         userId:sessionStorage.getItem("userId"),
//         processDefId:processDefId,
//         processGroupId:processGroupId,
//         boId:boId,
//         procesInstId:procesInstId,
//     }

//     // 获取权限
//     return formeditperm(param).then(res => {
//         const { code, data, msg } = res;
//         if (code === '0000') {
//             return data
//         } else {
//             this.$toast(msg);
//         }
//     });
// }

// 四舍五入精准
//s 为位数
export function toFixeds(num,s){
    let sums = Math.pow(10,s);
    let des = num * sums +0.5;
    des = parseInt(des,10) / sums;
    return des + ' ';
}
//乘运算
export function accMul(arg1, arg2) {

    let m = 0, s1 = arg1.toString(), s2 = arg2.toString();

    try { m += s1.split(".")[1].length } catch (e) { }

    try { m += s2.split(".")[1].length } catch (e) { }

    let sum=Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
    
    return sum;
}

//根据图片id 回显
export function setImgId(value){
    if(value){
        let path = process.env.NODE_ENV === 'development' ? '/api' : process.env.VUE_APP_BASE_URL;
            path = path + '/biz/bpmfile/getfile/';
        return path+value
    }
}